<template>
  <!-- 推荐商品 -->
  <div class="tuijian">
    <div
      class="tuijian-item"
      v-for="item in tuijian.slice(0, 4)"
      :key="item.id"
    >
      <a href="" @click.prevent="God(item.id)"
        ><img v-lazy="item.cover_url" alt=""
      /></a>
      <div>{{ item.title }}</div>
    </div>
  </div>
</template>

<script>
import { useRouter } from "vue-router";
export default {
  name: "TuijianView",
  //   接受父组件传来的数据
  props: {
    tuijian: {
      type: Array,
      //如果没有数据，那么为空数组
      default() {
        return [];
      },
    },
  },
  setup() {
    const router = useRouter();
    //跳转商品详情，传id
    let God = (id) => {
      router.push({ path: "/detail", query: { id } });
    };
    return {
      God,
    };
  },
};
</script>

<style>
.tuijian {
  display: flex;
  width: 100%;
  text-align: center;
  font-size: var(--font-size);
  padding: 15px 0px 30px;
  border-bottom: 8px solid #eee;
}
.tuijian-item {
  flex: 1;
}
.tuijian-item img {
  display: block;
  width: 70px;
  height: 70px;
  margin-bottom: 10px;
}
</style>